package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.TextArea;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerPrincipal;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

import javax.swing.ImageIcon;

public class TelaCadastrarInternacoes extends JFrame {

	private JPanel contentPane;
	static JTextField txt_dataEntrada;
	static JTextField txt_hospitalClinica;
	static JTextField txt_dataSaida;
	static JTextField txt_medico;
	static TextArea textMotivo;
	static Integer codAletrar;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastrarInternacoes frame = new TelaCadastrarInternacoes();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaCadastrarInternacoes() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 840, 540);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblInternaes = new JLabel("Interna\u00E7\u00E3o");
		lblInternaes.setForeground(new Color(0, 0, 128));
		lblInternaes.setFont(new Font("Franklin Gothic Medium Cond", Font.PLAIN, 25));
		lblInternaes.setBounds(34, 23, 112, 34);
		contentPane.add(lblInternaes);
		
		JLabel lblDataDeEntrada = new JLabel("Data de Entrada");
		lblDataDeEntrada.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDeEntrada.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDeEntrada.setBounds(63, 77, 124, 19);
		contentPane.add(lblDataDeEntrada);
		
		txt_dataEntrada = new JTextField();
		txt_dataEntrada.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataEntrada.setColumns(10);
		txt_dataEntrada.setBounds(197, 74, 124, 23);
		contentPane.add(txt_dataEntrada);
		
		txt_hospitalClinica = new JTextField();
		txt_hospitalClinica.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_hospitalClinica.setColumns(10);
		txt_hospitalClinica.setBounds(197, 139, 377, 23);
		contentPane.add(txt_hospitalClinica);
		
		JLabel label_2 = new JLabel("Hospital/Cl\u00EDnica:");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setFont(new Font("Arial", Font.PLAIN, 14));
		label_2.setBounds(63, 142, 124, 19);
		contentPane.add(label_2);
		
		JLabel lblDataDeSada = new JLabel("Data de Sa\u00EDda:");
		lblDataDeSada.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDeSada.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDeSada.setBounds(63, 109, 124, 19);
		contentPane.add(lblDataDeSada);
		
		txt_dataSaida = new JTextField();
		txt_dataSaida.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataSaida.setColumns(10);
		txt_dataSaida.setBounds(197, 107, 124, 23);
		contentPane.add(txt_dataSaida);
		
		textMotivo = new TextArea();
		textMotivo.setBounds(194, 206, 380, 208);
		contentPane.add(textMotivo);
		
		JLabel lblMotivo = new JLabel("Motivo:");
		lblMotivo.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMotivo.setFont(new Font("Arial", Font.PLAIN, 14));
		lblMotivo.setBounds(104, 206, 80, 19);
		contentPane.add(lblMotivo);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String dataEntrada = txt_dataEntrada.getText();
				String dataSaida = txt_dataSaida.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String motivo = textMotivo.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				control.InserirInternacao(dataEntrada, dataSaida, local, medico, motivo);
				TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
				telaMensagem.setLocationRelativeTo(null);
				telaMensagem.setVisible(true);
				txt_dataEntrada.setText("");
				txt_dataSaida.setText("");
				txt_hospitalClinica.setText("");
				txt_medico.setText("");
				textMotivo.setText("");
			}
		});
		btnSalvar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSalvar.setBounds(448, 434, 100, 43);
		contentPane.add(btnSalvar);
		
		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnSair.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSair.setBounds(557, 434, 100, 43);
		contentPane.add(btnSair);
		
		JLabel lblMdico = new JLabel("M\u00E9dico:");
		lblMdico.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMdico.setFont(new Font("Arial", Font.PLAIN, 14));
		lblMdico.setBounds(63, 176, 124, 19);
		contentPane.add(lblMdico);
		
		txt_medico = new JTextField();
		txt_medico.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_medico.setColumns(10);
		txt_medico.setBounds(197, 173, 377, 23);
		contentPane.add(txt_medico);
		
		JButton button_2 = new JButton("Deletar");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataEntrada = txt_dataEntrada.getText();
				String dataSaida = txt_dataSaida.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String motivo = textMotivo.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.deletarInternacao(codAletrar, dataEntrada, dataSaida, local, medico, motivo);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataEntrada.setText("");
					txt_dataSaida.setText("");
					txt_hospitalClinica.setText("");
					txt_medico.setText("");
					textMotivo.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		button_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button_2.setBackground(Color.WHITE);
		button_2.setBounds(338, 434, 100, 43);
		contentPane.add(button_2);
		
		JButton btnAlterar = new JButton("Alterar");
		btnAlterar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataEntrada = txt_dataEntrada.getText();
				String dataSaida = txt_dataSaida.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String motivo = textMotivo.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.editarInternacao(codAletrar, dataEntrada, dataSaida, local, medico, motivo);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataEntrada.setText("");
					txt_dataSaida.setText("");
					txt_hospitalClinica.setText("");
					txt_medico.setText("");
					textMotivo.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		btnAlterar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnAlterar.setBackground(Color.WHITE);
		btnAlterar.setBounds(226, 434, 100, 43);
		contentPane.add(btnAlterar);
		
		JButton btnListar = new JButton("Listar");
		btnListar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaListarInternacoes telaCadastraInformacoes = new TelaListarInternacoes();
				telaCadastraInformacoes.setLocationRelativeTo(null);
				telaCadastraInformacoes.setVisible(true);
			}
		});
		btnListar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnListar.setBackground(Color.WHITE);
		btnListar.setBounds(116, 434, 100, 43);
		contentPane.add(btnListar);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("arquivos\\FundoCadastros.png"));
		label.setBounds(0, -2, 834, 513);
		contentPane.add(label);
	}

}
